package com.wdb.common.configurer.feign;

import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import feign.Feign;
import feign.codec.ErrorDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@ConditionalOnClass({FeignClient.class, Feign.class})
public class FeignConfigurer extends WebMvcConfigurerAdapter {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Bean
    public ErrorDecoder errorDecoder() {
        if (logger.isDebugEnabled()) {
            logger.info("{}", "added feign error decoder");
        }

        return new FeignDecoder();
    }

    @Bean
    public HystrixConcurrencyStrategy hystrixConcurrencyStrategy() {
        return new FeignHystrixConcurrencyStrategy();
    }
}
